#
# @lc app=leetcode.cn id=976 lang=python3
#
# [976] 三角形的最大周长
#
from typing import List


# @lc code=start
class Solution:
    def largestPerimeter(self, A: List[int]) -> int:
        A.sort(reverse=True)
        i = 2
        while i < len(A):
            if A[i - 2] < A[i - 1] + A[i]:
                return A[i - 2] + A[i - 1] + A[i]
            i += 1
        return 0


# @lc code=end
if __name__ == "__main__":
    s = Solution()
    lst = [2, 1, 2]
    ret = s.largestPerimeter(lst)
    print(ret, 5)

    s = Solution()
    lst = [1, 2, 1]
    ret = s.largestPerimeter(lst)
    print(ret, 0)

    s = Solution()
    lst = [3, 2, 3, 4]
    ret = s.largestPerimeter(lst)
    print(ret, 10)

    s = Solution()
    lst = [3, 6, 2, 3]
    ret = s.largestPerimeter(lst)
    print(ret, 8)